// Program Loader for PCMod (SERVERSIDE)

AddCSLuaFile( "cl_programs.lua" )

ProgramList = {}

PROG = {}

Msg( "== Loading serverside programs... ==\n" )

local cnt = 0

local prog_folders = file.FindDir ("../lua/programs/*")

if (prog_folders) then

	for _,folder in pairs (prog_folders) do	
		// Add to our count
		cnt = cnt + 1
		
		// Redefine the table
		PROG = {}
		
		PROG.CodeName = folder
		PROG.Path = "programs/" .. PROG.CodeName .. "/"
		
		// Include the file
		include( PROG.Path .. "init.lua" )
		
		// Validate the required fields
		if (!PROG.PName) then PROG.PName = "Unknown" end
		if (!PROG.Name) then PROG.Name = "Unknown" end
		if (!PROG.Author) then PROG.Author = "Unknown" end
		if (!PROG.Exists) then PROG.Exists = true end
		
		AddCSLuaFile( "programs/cl_p_" .. string.lower(PROG.PName) .. ".lua" )
		
		// Add our own functions
		if (PCLIB) then table.Merge( PROG, PCLIB ) end
		
		// Add the item
		ProgramList[ PROG.PName ] = PROG
		
		// Notify the console
		Msg( "PCMod -> Program " .. PROG.PName .. " loaded!\n" )
	end
	
else
	Msg( "PCMod -> Warning, no programs found!\n" )
end

Msg( "PCMod -> " .. tostring( cnt ) .. " programs loaded!\n" )